<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
#headTag('修改密码和邮箱')
<script type="text/javascript">
$(document).ready(function(){
	$('form').submit(function(){
		$("input[type=submit]").attr("disabled", "disabled");
		$("span.error").remove();
		var validate = function(oldPassword, newPassword, _newPassword, email){
			var flag = true;
			if(oldPassword.length == 0){
				$('input[name=oldPassword]').after('<span class="error" style="color:red;">*原始密码必须填写</span>');
				flag = false;
			}
			if(newPassword.length != 0){
				if(newPassword.length < 6 || newPassword.length > 14){
					$('input[name=newPassword]').after('<span class="error" style="color:red;">*新密码的长度必须大于6个字符小于14个字符</span>');
					flag = false;
				}
				if(newPassword != _newPassword){
					$('input[name=_newPassword]').after('<span class="error" style="color:red;">*两次密码输入不一致</span>');
					flag = false;
				}
			}
			if(($.trim(email)).length == 0){
				$('input[name=email]').after('<span class="error" style="color:red;">*邮箱地址必须填写</span>');
				flag = false;
			}
			return flag;
		};
		var oldPassword = $('input[name=oldPassword]').val();
		var newPassword = $('input[name=newPassword]').val();
		var _newPassword = $('input[name=_newPassword]').val();
		var email = $('input[name=email]').val();
		
		if(validate(oldPassword, newPassword, _newPassword, email)){
			var data = {oldPassword:oldPassword, newPassword:newPassword, email:email};
			$.postJSON($(this).attr('action'), data, function(json){
				if(json.success){
					alert("操作成功");
				} else {
					for(var i=0;i<json.errors.length;i++){
						if(json.errors[i].element==null){
							alert(json.errors[i].message);
						}else {
							$("*[name='"+json.errors[i].element+"']").after('<span class="error" style="color:red;">*'+json.errors[i].message+'</span>');
						}
					}
				}
				$("input[type=submit]").removeAttr("disabled");
			}, "json");
		} else {
			$("input[type=submit]").removeAttr("disabled");
		}
		return false;
	});
});
</script>
</head>
<body>
<div id="page">
#parse("default/_header.htm")
<div id="middle">
<div id="main_wrap">
	<div id="main">
		#topbar()
		<div class="center">
			<h1>修改密码和邮箱</h1>
			<div class="content">
				<div class="password">
					<span class="notise">您必须填写原密码才能修改下面的资料</span>
					<form action="$url.base/account/$owner.id/password?_method=PUT" method="post">
					<table>
						<tr>
							<th>原密码:</th>
							<td width="265px"><input type="password" name="oldPassword"/><span class="error"></span></td>
							<td>必须填写</td>
						</tr>
						<tr>
							<th>新密码:</th>
							<td><input type="password" name="newPassword"/></td>
							<td>如果不修改密码不需要填写</td>
						</tr>
						<tr>
							<th>确认新密码:</th>
							<td><input type="password" name="_newPassword"/></td>
							<td>如果不修改密码不需要填写</td>
						</tr>
						<tr>
							<th>邮箱地址:</th>
							<td><input type="text" name="email" value="${owner.email}"/></td>
							<td></td>
						</tr>
						<tr>
							<th></th>
							<td><input type="submit" class="submit" value="提交"/></td>
							<td></td>
						</tr>
					</table>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
#parse("default/center/_sidebar.htm")
</div>
</div>
#parse("default/_footer.htm")
</body>
</html>